package com.ydy.ewallet.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @author Kephon
 */
public enum ErrorEnums {

    /**
     * 错误信息枚举
     */
    SUCCESS("0", "操作成功"),
    FAIL("1", "操作失败"),
    ILLEGAL_ARGUMENT_ERROR("400", "非法参数"),
    INTERNAL_SERVER_ERROR("500", "INTERNAL SERVER ERROR"),
    ACCESS_DENIED("403", "禁止访问"),
    COMMON_ERROR("9999", "未知错误"),
    NULL_ERROR("5000", "找不到记录");

    public static final Map<String, String> ERROR_CODE_MAP = new HashMap<>();

    static {
        ErrorEnums[] values = ErrorEnums.values();
        for (ErrorEnums ec : values) {
            ERROR_CODE_MAP.put(ec.getCode(), ec.getMsg());
        }
    }

    private String code;
    private String msg;

    ErrorEnums(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 获取错误提示的信息
     *
     * @param code 错误码
     * @return 错误提示信息
     */
    public static String getErrorMsg(String code) {
        return ERROR_CODE_MAP.get(code);
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getErrorCode() {
        return Integer.parseInt(code);
    }

}
